from typing import TypedDict, Literal, Optional, Annotated, List
import pandas as pd

class BaseQuantParams(TypedDict):
    """基础量化参数"""
    asset_class: Annotated[
        Literal["外汇", "国债", "政策性金融债", "贵金属"],
        "交易资产类别"
    ]
    time_frame: Annotated[
        Literal["1分钟", "15分钟", "1小时", "日线", "周线"],
        "策略时间粒度"
    ]
    max_drawdown: Annotated[
        float,
        "最大允许回撤（0-1之间）"
    ] = 0.2

class FXParams(TypedDict):
    """外汇专用参数"""
    currency_pair: Annotated[
        Literal["EUR/USD", "USD/JPY", "GBP/USD", "USD/CNH"],
        "外汇货币对"
    ]
    leverage_ratio: Annotated[
        float,
        "杠杆倍数"
    ]
    fx_data_sources: Annotated[
        List[Literal["L2订单簿", "宏观经济指标", "央行政策文本"]],
        "外汇数据源"
    ]

class BondParams(TypedDict):
    """债券专用参数"""
    bond_duration: Annotated[
        Literal["短端(1-3Y)", "中端(3-7Y)", "长端(7Y+)"],
        "债券久期分类"
    ]
    credit_rating: Annotated[
        Literal["AAA", "AA+", "AA"],
        "债券信用评级"
    ]
    bond_data_sources: Annotated[
        List[Literal["宏观经济指标", "央行政策文本"]],
        "债券数据源"
    ]

class MetalParams(TypedDict):
    """贵金属专用参数"""
    metal_type: Annotated[
        Literal["黄金", "白银", "铂金", "钯金"],
        "标的贵金属类型"
    ]
    market: Annotated[
        Literal["现货", "期货主力合约", "ETF"],
        "交易市场类型"
    ]
    volatility_profile: Annotated[
        Literal["低波动", "常态波动", "高波动"],
        "波动率特征模式"
    ]
    carry_cost: Annotated[
        float,
        "持仓成本"
    ]
    max_leverage: Annotated[
        float,
        "最大杠杆倍数"
    ] = 3.0
    metal_data_sources: Annotated[
        List[Literal["价格", "持仓量", "ETF流动", "美元指数", "通胀数据"]],
        "贵金属数据源"
    ]

class QuantParams(BaseQuantParams):
    """统一量化参数"""
    # 外汇参数 (仅当asset_class="外汇"时使用)
    fx_params: Annotated[
        Optional[FXParams],
        "外汇专用参数"
    ] = None

    # 债券参数 (仅当asset_class包含"国债"或"政策性金融债"时使用)
    bond_params: Annotated[
        Optional[BondParams],
        "债券专用参数"
    ] = None

    # 贵金属参数 (仅当asset_class="贵金属"时使用)
    metal_params: Annotated[
        Optional[MetalParams],
        "贵金属专用参数"
    ] = None

    # 通用数据源 (会被资产特定数据源覆盖)
    common_data_sources: Annotated[
        List[Literal["宏观经济指标", "央行政策文本"]],
        "通用数据源"
    ] = []
